<template>
	<view class="wrap">
		<view class="top">
			<view class="item">
				<view class="left">开户行名称</view>
				<input type="text" placeholder-class="line" v-model="bank_name" placeholder="请填写开户行名称" />
			</view>
			<view class="item">
				<view class="left">银行卡卡号</view>
				<input type="text" placeholder-class="line" v-model="bank_card" placeholder="请填写银行卡卡号" />
			</view>
			<view class="item">
				<view class="left">持有人姓名</view>
				<input type="text" placeholder-class="line" v-model="bank_account" placeholder="请填写持有人姓名" />
			</view>
			<view class="item">
				<view class="left">是否是公司</view>
				<switch :checked="is_company == 1" color="#20CBD4" @change="setCompany" />
			</view>
		</view>
		<view class="bottom">
			<view class="default">
				<view class="left">
					<view class="set">设置默认银行卡</view>
					<switch :checked="is_default == 1" color="#20CBD4" @change="setDefault" />
				</view>
				<view class="right tips"></view>
			</view>
		</view>
		<view class="save">
			<view class="btn" @click="saveBank">保存银行卡</view>
		</view>
		<u-toast ref="uToast" />
		<hoverMenu></hoverMenu>
	</view>
</template>

<script>
	import hoverMenu from "@/components/public/sa-hover-menu.vue";
	import {
		editBank
	} from "@/common/api.js";
	export default {
		components: {
			hoverMenu
		},
		data() {
			return {
				id: "",
				bank_name: "",
				bank_card: "",
				bank_account: "",
				is_company: 0,
				is_default: 0
			};
		},
		onLoad(options) {
			var bank = JSON.parse(options.bank)
			if (bank != "") {
				this.id = bank.id;
				this.bank_name = bank.bank_name;
				this.bank_card = bank.bank_card;
				this.bank_account = bank.bank_account;
				this.is_company = bank.is_company;
				this.is_default = bank.is_default;
			}
		},
		methods: {
			floatTouchClick(index) {
				this.$uniApi.floatTouch(index);
			},
			setCompany(e) {
				if (e.detail.value) {
					this.is_company = 1;
				} else {
					this.is_company = 0;
				}
			},
			setDefault(e) {
				if (e.detail.value) {
					this.is_default = 1;
				} else {
					this.is_default = 0;
				}
			},
			saveBank() {
				if (this.bank_name == '') {
					this.$refs.uToast.show({
						title: '请填写开户行名称',
					})
					return;
				}
				if (this.bank_card == '') {
					this.$refs.uToast.show({
						title: '请填写银行卡卡号',
					})
					return;
				}
				if (this.bank_account == '') {
					this.$refs.uToast.show({
						title: '请填写持有人姓名',
					})
					return;
				}
				editBank(this, {
					id: this.id,
					bank_name: this.bank_name,
					bank_card: this.bank_card,
					bank_account: this.bank_account,
					is_company: this.is_company,
					is_default: this.is_default
				});
			}
		}
	};
</script>
<style>
	page {
		background-color: #F6F6F6;
	}
</style>
<style lang="scss" scoped>
	/deep/ .line {
		color: $u-light-color;
		font-size: 28rpx;
	}

	.wrap {
		background-color: #f2f2f2;

		.top {
			background-color: #ffffff;
			border-top: solid 2rpx $u-border-color;
			padding: 22rpx;

			.item {
				display: flex;
				font-size: 32rpx;
				line-height: 100rpx;
				align-items: center;
				border-bottom: solid 2rpx $u-border-color;

				.left {
					width: 220rpx;
				}

				input {
					text-align: left;
				}
			}

			.address {
				padding: 20rpx 0;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}
			}

			.site-clipboard {
				padding-right: 40rpx;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}

				.clipboard {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: $u-tips-color;
					height: 80rpx;

					.icon {
						margin-top: 6rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.bottom {
			margin-top: 20rpx;
			padding: 40rpx;
			padding-right: 0;
			background-color: #ffffff;
			font-size: 28rpx;

			.tag {
				display: flex;

				.left {
					width: 160rpx;
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.tags {
						width: 140rpx;
						padding: 16rpx 8rpx;
						border: solid 2rpx $u-border-color;
						text-align: center;
						border-radius: 50rpx;
						margin: 0 10rpx 20rpx;
						display: flex;
						font-size: 28rpx;
						align-items: center;
						justify-content: center;
						color: $u-content-color;
						line-height: 1;
					}

					.plus {
						//padding: 10rpx 0;
					}
				}
			}

			.default {
				padding-bottom: 40rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: solid 2rpx $u-border-color;
				line-height: 64rpx;

				.tips {
					color: #909399;
					font-size: 24rpx;
				}

				.right {}
			}
		}
	}

	.save {
		margin-top: 300rpx;
		width: 100%;
		height: 120upx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.save view {
		display: flex;
	}

	.save .btn {
		background-color: #20CBD4;
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.4);
		width: 70%;
		height: 80upx;
		border-radius: 80upx;
		color: #fff;
		justify-content: center;
		align-items: center;
		font-size: 30upx;
	}
</style>